package com.itheima.app.controller;

import com.itheima.app.manager.SlideCardsManager;
import com.itheima.app.manager.UserCountsManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 数据统计
 *
 * @author DogeGuo
 */
@RestController
public class UserCountsController {

    @Autowired
    UserCountsManager userCountsManager;

    /**
     * 显示互相喜欢、喜欢、粉丝数量
     *
     * @return
     */
    @GetMapping("/users/counts")
    public ResponseEntity userLikeEachOther() {
        return userCountsManager.userLikeEachOther();
    }

    /**
     * 查询互相喜欢、喜欢、粉丝详情
     *
     * @param type
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/users/friends/{type}")
    public ResponseEntity LikeDetails(@PathVariable String type,
                                      @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return userCountsManager.LikeDetails(type, pageNum, pageSize);
    }

    @Autowired
    SlideCardsManager slideCardsManager;

    /**
     * 喜欢
     *
     * @param uid
     */
    @PostMapping("/users/fans/{uid}")
    public void someLike(@PathVariable String uid) {
        //获得当前用户的id
        long likeUserId = Long.parseLong(uid);
        slideCardsManager.saveLove(likeUserId);
    }

    /**
     * 取消喜欢
     *
     * @param uid
     */
    @DeleteMapping("/users/like/{uid}")
    public void deleteLike(@PathVariable String uid) {
        //获得当前用户的id
        long likeUserId = Long.parseLong(uid);
        slideCardsManager.removeLove(likeUserId);
    }
}
